use serde::Deserialize;
use serde::Serialize;
use ts_rs::TS;
use yata::core::PeriodType;
use yata::core::ValueType;

use super::IndicatorActionWrap;

///
/// Struct to hold the results of Struct yata::indicators::Envelopes Envelopes

///
///  参见[EVL](https://www.investopedia.com/terms/e/envelope.asp)
///
#[derive(Serialize, Deserialize, Default, Debug, TS, Clone)]
#[ts(export)]
pub struct EVL {
    ///1 signal
    ///Signal 1 appears when Source2 value crosses bounds.
    /// When Source2 value crosses upper bound upwards, returns full sell signal.
    /// When Source2 value crosses lower bound downwards, returns full buy signal.
    ///
    pub signal0: Option<IndicatorActionWrap>,

    ///3 values
    ///Upper bound
    ///Range of values is the same as the range of the source values.
    pub upper: ValueType,

    ///Lower bound
    ///Range of values is the same as the range of the source values.Action
    pub lower: ValueType,

    ///Raw Source2 value
    pub source2: ValueType,
}

/// Configuration
#[derive(Serialize, Deserialize, Debug, TS, Clone, Copy)]
#[ts(export)]
pub struct EVLConfig {
    /// ma: M
    /// Main moving average type.
    ///
    /// Default is SMA(20).
    ///
    /// Period range in [2; PeriodType::MAX).
    pub ma: PeriodType,

    /// k: ValueType
    /// Bound relative size. Default is 0.1.
    ///
    /// Range in (0.0; +inf).
    pub k: ValueType,
    // source: Source
    // Source value type for bounds. Default is Close.
    //
    // source2: Source
    // Source2 value type for actual price. Default is Close.
}

impl Default for EVLConfig {
    fn default() -> Self {
        Self { ma: 20, k: 0.1 }
    }
}
